<CsoundSynthesizer>
<CsOptions>
;-odac -iadc -d -m0 -b2048 -B4096 -+rtaudio=alsa -+rtmidi=alsa
-odac -B2048 -b1024 -d -+rtaudio=alsa
</CsOptions>
<CsInstruments>
/* add -M0 if you have MIDI (possibly -+rtmidi=virtual) */ 
sr=22050
kr = 441
ksmps=50
nchnls=2

;gas init 0

gas1 init 0
gas2 init 0

instr 1
  kt chnget "tempo"
  km = kt/240
  ktrig metro km 
  if (ktrig == 0) goto continue
    kvs1 chnget "vol1"
    krv1 chnget "rev1"
    km1  chnget "mute1"
    kpn1 chnget "pan1"
    kcut1 chnget "cut1"
    event "i", 2.1, 0, -1, 10, kvs1, krv1, km1, kpn1, kcut1
    kvs2 chnget "vol2"
    krv2 chnget "rev2"
    km2  chnget "mute2"
    kpn2 chnget "pan2"
    kcut2 chnget "cut2"
    event "i", 2.2, 0, -1, 11, kvs2, krv2, km2, kpn2, kcut2
    kvs3 chnget "vol3"
    krv3 chnget "rev3"
    km3  chnget "mute3"
    kpn3 chnget "pan3"
    kcut3 chnget "cut3"
    event "i", 2.3, 0, -1, 12, kvs3, krv3, km3, kpn3, kcut3
    kvs4 chnget "vol4"
    krv4 chnget "rev4"
    km4  chnget "mute4"
    kpn4 chnget "pan4"
    kcut4 chnget "cut4"
    event "i", 2.4, 0, -1, 13, kvs4, krv4, km4, kpn4, kcut4
    kvs5 chnget "vol5"
    krv5 chnget "rev5"
    km5  chnget "mute5"
    kpn5 chnget "pan5"
    kcut5 chnget "cut5"
    event "i", 2.5, 0, -1, 14, kvs5, krv5, km5, kpn5, kcut5
    kvs6 chnget "vol6"
    krv6 chnget "rev6"
    km6  chnget "mute6"
    kpn6 chnget "pan6"
    kcut6 chnget "cut6"
    event "i", 2.6, 0, -1, 15, kvs6, krv6, km6, kpn6, kcut6
  continue:
endin

instr 2
  S1 chnget "soundfile1"
  S2 chnget "soundfile2"
  S3 chnget "soundfile3"
  S4 chnget "soundfile4"
  S5 chnget "soundfile5"
  S6 chnget "soundfile6"
  strset 10, S1
  strset 11, S2
  strset 12, S3
  strset 13, S4
  strset 14, S5
  strset 15, S6

  itempo chnget "tempo"
  ibps = itempo/60

  Sname strget p4
  puts Sname, 1
  kp = 1-(2*p6)  ; 1,0 of button mapped to -1, 1
  kv  tonek p5 * (1-p7)/10, 10
  i1 strcmp Sname,"0"
  if (i1 == 0) goto end
    am diskin p4, kp

    if p9==0 goto nocutup
      acut bbcutm am, ibps, 4, 1, 1, 1
      asig = acut * kv
      goto outputit
    nocutup:
    asig = am * kv
    outputit:
    asig1, asig2 pan2 asig, p8

    gas1 = gas1 + asig1
    gas2 = gas2 + asig2

    end:
endin

instr 3
  S7 chnget "soundfile7"
  kvs7 chnget "vol7"
  krv7 chnget "rev7"

  kp = 1-(2*krv7)  ; 1,0 of button mapped to -1, 1
  kv  tonek kvs7/10, 10
  i1 strcmp S7,"0"
  if (i1 == 0) goto end
    am diskin S7, kp  
    asig = am * kv
    ;gas = gas + asig
  end:
endin

instr 4
  S8 chnget "soundfile8"
  kvs8 chnget "vol8"
  krv8 chnget "rev8"

  kp = 1-(2*krv8)  ; 1,0 of button mapped to -1, 1
  kv  tonek kvs8/10, 10
  i1 strcmp S8,"0"
  if (i1 == 0) goto end
    am diskin S8, kp  
    asig = am * kv
    ;gas = gas + asig
  end:
endin

;instr 5
;  kbypass chnget "bypass"
;  if kbypass==1 goto bypass
;    kthresh chnget "Th"
;    kratio chnget "Rt"
;    katt chnget "Att"
;    krel chnget "Rel"
;    ilook = 0.01
;    acomp1 compress gas1, gas1, kthresh, 48, 60, kratio, katt, krel, ilook
;    acomp2 compress gas2, gas2, kthresh, 48, 60, kratio, katt, krel, ilook
;    gas1 = acomp1
;    gas2 = acomp2
;bypass:
;endin

instr 9
  S1 chnget "output_file"
  i1 strcmp S1, "0"
  if i1 != 0 goto continue
    puts "no filename selected", 1
    turnoff
    goto end
  continue:
  ;fout S1, 2, gas
  fout S1, 2, gas1, gas2
  end:
endin

instr 10

; compressor settings
;  kbypass chnget "byps"  ; compressor bypass
;  kthresh chnget "Th"
;  kratio chnget "Rt"
;  katt chnget "Att"
;  krel chnget "Rel"
  kmugain chnget "Gain"
;  ilook = 0.01
;  iloknee = 48
;  ihiknee = 60

;  if kbypass==1 goto end
;      acomp1 compress gas1, gas1, kthresh, 48, 60, kratio, katt, krel, ilook
;      acomp2 compress gas2, gas2, kthresh, 48, 60, kratio, katt, krel, ilook
;      gas1 = acomp1 * kmugain
;      gas2 = acomp2 * kmugain

;  end:
  gas1 = gas1 * kmugain
  gas2 = gas2 * kmugain
  outs gas1, gas2
;  gas  = 0
  gas1  = 0
  gas2  = 0
endin

;instr 11
   ; keep going
;endin

</CsInstruments>

<CsScore>

i 10 0 3600

</CsScore>
</CsoundSynthesizer>
